package com.yy.thrid.controller;

import com.yy.thrid.enums.Status;
import com.yy.thrid.vo.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yangyao
 * @Description: UserController控制器
 * @date 2018/10/18 14:51
 */
@RestController
@RequestMapping(value = "/users")
public class UserController {

    @GetMapping(value = "/all")
    public List<User> getUsers() {
        List<User> userList = new ArrayList<User>();
        User user = null;
        for (int i = 0; i < 3; i++) {
            user = new User();
            user.setId(Long.valueOf(i));
            user.setUserName(i + "用户名");
            user.setPassword(i + "密码");
            user.setAge(i + 20);
            user.setStatus(i % 2 == 0 ? Status.VALID : Status.INVALID);
            userList.add(user);
        }
        return userList;
    }

    @GetMapping(value = "/nullStringTest")
    public List<User> nullStringTest() {
        List<User> userList = new ArrayList<User>();
        User user = null;
        for (int i = 0; i < 3; i++) {
            user = new User();
            user.setId(Long.valueOf(i));
            user.setUserName("");
            user.setPassword(null);
            user.setAge(i + 20);
            user.setStatus(i % 2 == 0 ? Status.VALID : Status.INVALID);
            userList.add(user);
        }
        return userList;
    }


    @GetMapping(value = "/mapTest")
    public Map<String, Object> mapTest() {
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        user.setId(Long.valueOf(1));
        user.setUserName("用户名");
        user.setPassword("密码");
        user.setAge(20);
        user.setStatus(Status.VALID);
        map.put("user", user);
        return map;
    }

    @GetMapping(value = "/nullMapTest")
    public Map<String, Object> nullMapTest() {
        Map<String, Object> map = new HashMap<>();
        map.put("user", null);
        return map;
    }
}
